home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / os2 / adaptor.zip / ADAPT.ZIP / adaptor / dalib / pvm3 / hostnd1.c < prev    next >
C/C++ Source or Header  |  1993-11-30  |  16KB  |  527 lines

  1. /**************************************************************************
  2. *                                                                         *
  3. *  Author      : Dr. Thomas Brandes, GMD, I1.HR                           *
  4. *  Copyright   : GMD St. Augustin, Germany                                *
  5. *  Date        : Aug 92                                                   *
  6. *  Last Update : Aug 92                                                   *
  7. *                                                                         *
  8. *  This Module is part of the DALIB                                       *
  9. *                                                                         *
  10. *  Module      : hostnode1.c                                              *
  11. *                                                                         *
  12. *  Function    : Moving full arrays between host and nodes                *
  13. *                                                                         *
  14. *  Export :  FORTRAN Interface                                            *
  15. *                                                                         *
  16. **************************************************************************/
  17.  
  18. #undef DEBUG
  19.  
  20. #include "system.h"
  21.  
  22.      /*********************************************************
  23.      *                                                        *
  24.      *  HOSTARRAY = NODEARRAY (x1:y1)                         *
  25.      *                                                        *
  26.      *********************************************************/
  27.  
  28. void dalib_host_node1__ (a, size, N1, x1, y1)
  29. unsigned char *a;
  30. int *size;
  31. int *N1, *x1, *y1;
  32.  
  33. {   int pid_low, pid_up, send_pid;
  34.     int my_pid;
  35.     unsigned char *a_ptr;
  36.  
  37.     int send_size;
  38.     int low, up;
  39.  
  40.     my_pid = pcb.i;
  41.  
  42. #ifdef DEBUG
  43.     printf ("Process %d calls host_node1 %d : %d\n", my_pid, *x1, *y1);
  44. #endif
  45.  
  46.     /* pid_low : pid_up =  processors that own elements of this range */
  47.  
  48.     if (my_pid == 0)
  49.  
  50.       { /* HOST recvs the data */
  51.         pid_low = dalib_where (*N1, *x1);
  52.         pid_up  = dalib_where (*N1, *y1);
  53.  
  54.         a_ptr = a;
  55.  
  56.         for (send_pid = pid_low; send_pid <= pid_up; send_pid ++)
  57.  
  58.           { /* get range , size */
  59.  
  60.             dalib_local_extensions (send_pid, *N1, &low, &up);
  61.             if (low < *x1) low = *x1;
  62.             if (up  > *y1) up  = *y1;
  63.  
  64.             /* host gets a(low:up) from processor i */
  65.             
  66.             send_size = (up - low + 1) * *size;
  67.             areceive (0, send_pid, a_ptr, send_size);
  68.             a_ptr += send_size;
  69.           }
  70.       }
  71.  
  72.      else
  73.       { /* look for data to send */
  74.  
  75.         dalib_local_slice__ (N1, x1, y1, &low, &up);
  76.         if (low <= up)
  77.           {  dalib_setup_section1 (*size, *N1, low, up);
  78.              dalib_send_section1 (0, a);
  79.           }
  80.       }
  81. } /* dalib_host_node1 */
  82.  
  83.      /*********************************************************
  84.      *                                                        *
  85.      *  NODEARRAY (x1:y1) = HOSTARRAY                         *
  86.      *                                                        *
  87.      *********************************************************/
  88.  
  89. void dalib_node_host1__ (a, size, N1, x1, y1)
  90. unsigned char *a;
  91. int *size;
  92. int *N1, *x1, *y1;
  93.  
  94. {   int pid_low, pid_up, send_pid;
  95.     int my_pid;
  96.     unsigned char *a_ptr;
  97.  
  98.     int send_size;
  99.     int low, up;
  100.  
  101.     my_pid = pcb.i;
  102.  
  103. #ifdef DEBUG
  104.     printf ("Process %d calls node_host1 %d : %d\n", my_pid, *x1, *y1);
  105. #endif
  106.  
  107.     /* pid_low : pid_up =  processors that own elements of this range */
  108.  
  109.     if (my_pid == 0)
  110.  
  111.       { /* HOST sends the data */
  112.         pid_low = dalib_where (*N1, *x1);
  113.         pid_up  = dalib_where (*N1, *y1);
  114.  
  115.         a_ptr = a;
  116.  
  117.         for (send_pid = pid_low; send_pid <= pid_up; send_pid++)
  118.  
  119.           { /* get range */
  120.  
  121.             dalib_local_extensions (send_pid, *N1, &low, &up);
  122.             if (low < *x1) low = *x1;
  123.             if (up  > *y1) up  = *y1;
  124.  
  125.             /* host sends a(low:up) to processor send_pid */
  126.             
  127.             send_size = (up - low + 1) * *size;
  128.             asend (0, send_pid, a_ptr, send_size);
  129.             a_ptr += send_size;
  130.           }
  131.       }
  132.  
  133.      else
  134.  
  135.       { /* look for data to recv */
  136.  
  137.         dalib_local_slice__ (N1, x1, y1, &low, &up);
  138.         if (low <= up)
  139.           {  dalib_setup_section1 (*size, *N1, low, up);
  140.              dalib_recv_section1 (0, a);
  141.           }
  142.       }
  143. } /* dalib_node_host1 */
  144.  
  145.      /*********************************************************
  146.      *                                                        *
  147.      *  HOSTARRAY = NODEARRAY (x1:y1,x2:y2)                   *
  148.      *                                                        *
  149.      *********************************************************/
  150.  
  151. void dalib_host_node2__ (a, size, N1, x1, y1, N2, x2, y2)
  152. unsigned char *a;
  153. int *size;
  154. int *N1, *x1, *y1, *N2, *x2, *y2;
  155.  
  156. {   int pid_low, pid_up, send_pid;
  157.     int my_pid;
  158.     unsigned char *a_ptr;
  159.  
  160.     int send_size;
  161.     int low, up;
  162.  
  163.     my_pid = pcb.i;
  164.  
  165. #ifdef DEBUG
  166.     printf ("Process %d calls host_node2 %d : %d, %d : %d\n", 
  167.              my_pid, *x1, *y1, *x2, *y2);
  168. #endif
  169.  
  170.     /* pid_low : pid_up =  processors that own elements of this range */
  171.  
  172.     if (my_pid == 0)
  173.  
  174.       { /* HOST recvs the data */
  175.         pid_low = dalib_where (*N2, *x2);
  176.         pid_up  = dalib_where (*N2, *y2);
  177.  
  178.         a_ptr = a;
  179.  
  180.         for (send_pid = pid_low; send_pid <= pid_up; send_pid ++)
  181.  
  182.           { /* get range , size */
  183.  
  184.             dalib_local_extensions (send_pid, *N2, &low, &up);
  185.             if (low < *x2) low = *x2;
  186.             if (up  > *y2) up  = *y2;
  187.  
  188.             /* host gets a(low:up) from processor i */
  189.             
  190.             send_size = (up - low + 1) * (*y1 - *x1 + 1) * *size;
  191.             areceive (0, send_pid, a_ptr, send_size);
  192.             a_ptr += send_size;
  193.           }
  194.       }
  195.  
  196.      else
  197.       { /* look for data to send */
  198.  
  199.         dalib_local_slice__ (N2, x2, y2, &low, &up);
  200.         if (low <= up)
  201.           {  dalib_setup_section2 (*size, *N1, *x1, *y1, *N2, low, up);
  202.              dalib_send_section2 (0, a);
  203.           }
  204.       }
  205. } /* dalib_host_node2 */
  206.  
  207.      /*********************************************************
  208.      *                                                        *
  209.      *  NODEARRAY (x1:y1,x2:y2) = HOSTARRAY                   *
  210.      *                                                        *
  211.      *********************************************************/
  212.  
  213. void dalib_node_host2__ (a, size, N1, x1, y1, N2, x2, y2)
  214. unsigned char *a;
  215. int *size;
  216. int *N1, *x1, *y1, *N2, *x2, *y2;
  217.  
  218. {   int pid_low, pid_up, send_pid;
  219.     int my_pid;
  220.     unsigned char *a_ptr;
  221.  
  222.     int send_size;
  223.     int low, up;
  224.  
  225.     my_pid = pcb.i;
  226.  
  227. #ifdef DEBUG
  228.     printf ("Process %d calls node_host2 %d : %d, %d : %d\n", 
  229.              my_pid, *x1, *y1, *x2, *y2);
  230. #endif
  231.  
  232.     /* pid_low : pid_up =  processors that own elements of this range */
  233.  
  234.     if (my_pid == 0)
  235.  
  236.       { /* HOST sends the data */
  237.         pid_low = dalib_where (*N2, *x2);
  238.         pid_up  = dalib_where (*N2, *y2);
  239.  
  240.         a_ptr = a;
  241.  
  242.         for (send_pid = pid_low; send_pid <= pid_up; send_pid++)
  243.  
  244.           { /* get range */
  245.  
  246.             dalib_local_extensions (send_pid, *N2, &low, &up);
  247.             if (low < *x2) low = *x2;
  248.             if (up  > *y2) up  = *y2;
  249.  
  250.             /* host sends a(low:up) to processor send_pid */
  251.             
  252.             send_size = (up - low + 1) * (*y1 - *x1 + 1) * *size;
  253.             asend (0, send_pid, a_ptr, send_size);
  254.             a_ptr += send_size;
  255.           }
  256.       }
  257.  
  258.      else
  259.  
  260.       { /* look for data to recv */
  261.  
  262.         dalib_local_slice__ (N2, x2, y2, &low, &up);
  263.         if (low <= up)
  264.           {  dalib_setup_section2 (*size, *N1, *x1, *y1, *N2, low, up);
  265.              dalib_recv_section2 (0, a);
  266.           }
  267.       }
  268. } /* dalib_node_host2 */
  269.  
  270.      /*********************************************************
  271.      *                                                        *
  272.      *  HOSTARRAY = NODEARRAY (x1:y1,x2:y2,x3:y3)             *
  273.      *                                                        *
  274.      *********************************************************/
  275.  
  276. void dalib_host_node3__ (a, size, N1, x1, y1, N2, x2, y2, N3, x3, y3)
  277. unsigned char *a;
  278. int *size;
  279. int *N1, *x1, *y1, *N2, *x2, *y2, *N3, *x3, *y3;
  280.  
  281. {   int pid_low, pid_up, send_pid;
  282.     int my_pid;
  283.     unsigned char *a_ptr;
  284.  
  285.     int send_size;
  286.     int low, up;
  287.  
  288.     my_pid = pcb.i;
  289.  
  290. #ifdef DEBUG
  291.     printf ("Process %d calls host_node3 %d : %d, %d : %d, %d : %d\n", 
  292.              my_pid, *x1, *y1, *x2, *y2, *x3, *y3);
  293. #endif
  294.  
  295.     /* pid_low : pid_up =  processors that own elements of this range */
  296.  
  297.     if (my_pid == 0)
  298.  
  299.       { /* HOST recvs the data */
  300.         pid_low = dalib_where (*N3, *x3);
  301.         pid_up  = dalib_where (*N3, *y3);
  302.  
  303.         a_ptr = a;
  304.  
  305.         for (send_pid = pid_low; send_pid <= pid_up; send_pid ++)
  306.  
  307.           { /* get range , size */
  308.  
  309.             dalib_local_extensions (send_pid, *N3, &low, &up);
  310.             if (low < *x3) low = *x3;
  311.             if (up  > *y3) up  = *y3;
  312.  
  313.             /* host gets a(low:up) from processor i */
  314.             
  315.             send_size = (up - low + 1) * (*y1 - *x1 + 1) * 
  316.                         (*y2 - *x2 + 1) * *size;
  317.             areceive (0, send_pid, a_ptr, send_size);
  318.             a_ptr += send_size;
  319.           }
  320.       }
  321.  
  322.      else
  323.       { /* look for data to send */
  324.  
  325.         dalib_local_slice__ (N3, x3, y3, &low, &up);
  326.         if (low <= up)
  327.           {  dalib_setup_section3 (*size, *N1, *x1, *y1, *N2, *x2, *y2,
  328.                                           *N3, low, up);
  329.              dalib_send_section3 (0, a);
  330.           }
  331.       }
  332. } /* dalib_host_node3 */
  333.  
  334.      /*********************************************************
  335.      *                                                        *
  336.      *  NODEARRAY (x1:y1,x2:y2,x3:y3) = HOSTARRAY             *
  337.      *                                                        *
  338.      *********************************************************/
  339.  
  340. void dalib_node_host3__ (a, size, N1, x1, y1, N2, x2, y2, N3, x3, y3)
  341. unsigned char *a;
  342. int *size;
  343. int *N1, *x1, *y1, *N2, *x2, *y2, *N3, *x3, *y3;
  344.  
  345. {   int pid_low, pid_up, send_pid;
  346.     int my_pid;
  347.     unsigned char *a_ptr;
  348.  
  349.     int send_size;
  350.     int low, up;
  351.  
  352.     my_pid = pcb.i;
  353.  
  354. #ifdef DEBUG
  355.     printf ("Process %d calls node_host3 %d : %d, %d : %d, %d : %d\n", 
  356.              my_pid, *x1, *y1, *x2, *y2, *x3, *y3);
  357. #endif
  358.  
  359.     /* pid_low : pid_up =  processors that own elements of this range */
  360.  
  361.     if (my_pid == 0)
  362.  
  363.       { /* HOST sends the data */
  364.         pid_low = dalib_where (*N3, *x3);
  365.         pid_up  = dalib_where (*N3, *y3);
  366.  
  367.         a_ptr = a;
  368.  
  369.         for (send_pid = pid_low; send_pid <= pid_up; send_pid++)
  370.  
  371.           { /* get range */
  372.  
  373.             dalib_local_extensions (send_pid, *N3, &low, &up);
  374.             if (low < *x3) low = *x3;
  375.             if (up  > *y3) up  = *y3;
  376.  
  377.             /* host sends a(low:up) to processor send_pid */
  378.             
  379.             send_size = (up - low + 1)  * (*y1 - *x1 + 1) * 
  380.                         (*y2 - *x2 + 1) * *size;
  381.             asend (0, send_pid, a_ptr, send_size);
  382.             a_ptr += send_size;
  383.           }
  384.       }
  385.  
  386.      else
  387.  
  388.       { /* look for data to recv */
  389.  
  390.         dalib_local_slice__ (N3, x3, y3, &low, &up);
  391.         if (low <= up)
  392.           {  dalib_setup_section3 (*size, *N1, *x1, *y1, *N2, *x2, *y2,
  393.                                           *N3, low, up);
  394.              dalib_recv_section3 (0, a);
  395.           }
  396.       }
  397. } /* dalib_node_host3 */
  398.  
  399.      /*********************************************************
  400.      *                                                        *
  401.      *  HOSTARRAY = NODEARRAY (x1:y1,x2:y2,x3:y3,x4:y4)       *
  402.      *                                                        *
  403.      *********************************************************/
  404.  
  405. void dalib_host_node4__ (a, size, N1, x1, y1, N2, x2, y2, N3, x3, y3, N4, x4, y4)
  406. unsigned char *a;
  407. int *size;
  408. int *N1, *x1, *y1, *N2, *x2, *y2, *N3, *x3, *y3, *N4, *x4, *y4;
  409.  
  410. {   int pid_low, pid_up, send_pid;
  411.     int my_pid;
  412.     unsigned char *a_ptr;
  413.  
  414.     int send_size;
  415.     int low, up;
  416.  
  417.     my_pid = pcb.i;
  418.  
  419. #ifdef DEBUG
  420.     printf ("Process %d calls host_node4 %d : %d, %d : %d, %d : %d, %d : %d\n", 
  421.              my_pid, *x1, *y1, *x2, *y2, *x3, *y3, *x4, *y4);
  422. #endif
  423.  
  424.     /* pid_low : pid_up =  processors that own elements of this range */
  425.  
  426.     if (my_pid == 0)
  427.  
  428.       { /* HOST recvs the data */
  429.         pid_low = dalib_where (*N4, *x4);
  430.         pid_up  = dalib_where (*N4, *y4);
  431.  
  432.         a_ptr = a;
  433.  
  434.         for (send_pid = pid_low; send_pid <= pid_up; send_pid ++)
  435.  
  436.           { /* get range , size */
  437.  
  438.             dalib_local_extensions (send_pid, *N4, &low, &up);
  439.             if (low < *x4) low = *x4;
  440.             if (up  > *y4) up  = *y4;
  441.  
  442.             /* host gets a(low:up) from processor i */
  443.             
  444.             send_size = (up - low + 1) * (*y1 - *x1 + 1) * 
  445.                         (*y2 - *x2 + 1) * (*y3 - *x3 + 1) * *size;
  446.             areceive (0, send_pid, a_ptr, send_size);
  447.             a_ptr += send_size;
  448.           }
  449.       }
  450.  
  451.      else
  452.       { /* look for data to send */
  453.  
  454.         dalib_local_slice__ (N4, x4, y4, &low, &up);
  455.         if (low <= up)
  456.           {  dalib_setup_section4 (*size, *N1, *x1, *y1, *N2, *x2, *y2,
  457.                                           *N3, *x3, *y3, *N4, low, up);
  458.              dalib_send_section4 (0, a);
  459.           }
  460.       }
  461. } /* dalib_host_node4 */
  462.  
  463.      /*********************************************************
  464.      *                                                        *
  465.      *  NODEARRAY (x1:y1,x2:y2,x3:y3,x4:y4) = HOSTARRAY       *
  466.      *                                                        *
  467.      *********************************************************/
  468.  
  469. void dalib_node_host4__ (a, size, N1, x1, y1, N2, x2, y2, N3, x3, y3, N4, x4, y4)
  470. unsigned char *a;
  471. int *size;
  472. int *N1, *x1, *y1, *N2, *x2, *y2, *N3, *x3, *y3, *N4, *x4, *y4;
  473.  
  474. {   int pid_low, pid_up, send_pid;
  475.     int my_pid;
  476.     unsigned char *a_ptr;
  477.  
  478.     int send_size;
  479.     int low, up;
  480.  
  481.     my_pid = pcb.i;
  482.  
  483. #ifdef DEBUG
  484.     printf ("Process %d calls node_host4 %d : %d, %d : %d, %d : %d, %d : %d\n", 
  485.              my_pid, *x1, *y1, *x2, *y2, *x3, *y3, *x4, *y4);
  486. #endif
  487.  
  488.     /* pid_low : pid_up =  processors that own elements of this range */
  489.  
  490.     if (my_pid == 0)
  491.  
  492.       { /* HOST sends the data */
  493.         pid_low = dalib_where (*N4, *x4);
  494.         pid_up  = dalib_where (*N4, *y4);
  495.  
  496.         a_ptr = a;
  497.  
  498.         for (send_pid = pid_low; send_pid <= pid_up; send_pid++)
  499.  
  500.           { /* get range */
  501.  
  502.             dalib_local_extensions (send_pid, *N4, &low, &up);
  503.             if (low < *x4) low = *x4;
  504.             if (up  > *y4) up  = *y4;
  505.  
  506.             /* host sends a(low:up) to processor send_pid */
  507.             
  508.             send_size = (up - low + 1)  * (*y1 - *x1 + 1) * 
  509.                         (*y2 - *x2 + 1) * (*y3 - *x3 + 1) * *size;
  510.             asend (0, send_pid, a_ptr, send_size);
  511.             a_ptr += send_size;
  512.           }
  513.       }
  514.  
  515.      else
  516.  
  517.       { /* look for data to recv */
  518.  
  519.         dalib_local_slice__ (N4, x4, y4, &low, &up);
  520.         if (low <= up)
  521.           {  dalib_setup_section4 (*size, *N1, *x1, *y1, *N2, *x2, *y2,
  522.                                           *N3, *x3, *y3, *N4, low, up);
  523.              dalib_recv_section4 (0, a);
  524.           }
  525.       }
  526. } /* dalib_node_host4 */
  527.